                
num_dict = {'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5,
            'six': 6, 'seven': 7, 'eight': 8, 'nine': 9}

def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True


def find_nearest_prime(n):
    up = n + 1
    down = n - 1
    while True:
        if is_prime(up):
            return up
        if is_prime(down):
            return down
        up += 1
        down -= 1


def main():
    words = input("Введите три слова через пробел: ").split()
    if len(words) != 3:
        print("Wrong input")
        return

    try:
        num = int(''.join(str(num_dict[word]) for word in words))
    except (KeyError, ValueError):
        print("Wrong input")
        return

    if num < 100 or num > 999:
        print("Wrong input")
        return

    nearest_prime = find_nearest_prime(num)
    print(nearest_prime)

if __name__ == '__main__':
    main()
